home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / SCREEN.SWG / 0032_Direct Write & Scroll.pas < prev    next >
Pascal/Delphi Source File  |  1993-08-27  |  4KB  |  114 lines

  1. {
  2. LOU DUCHEZ
  3.  
  4. >I have two questions. First, How can I display ANSI files from a Pascal
  5. >program by using the CON driver (read: ANSI.SYS) instead of going to the
  6. >trouble of writing a terminal emulator, and still remain
  7. >window-relative? I used TP5.5's WRITE procedure to write to a file
  8. >assigned to the CON device instead of the CRT unit's standard OutPut,
  9. >but this obliterated my status line at the bottom of the screen when the
  10. >ANSI file scrolled. Is there an easy way to write to the CON device
  11. >while remaining window-relative without having to modify ANSI.SYS or
  12. >write a terminal emulation procedure?
  13. > My second question: How can I call a batch file from within a Pascal
  14. >program and pass %1-%9 parameters to it? I'm aware of the EXEC
  15. >procedure, but doesn't that only work on executables?
  16.  
  17. Second question first: you're right about EXEC calling only executables.
  18. So try calling "COMMAND.COM" as your program, and give it parameters of
  19. "/C " plus the batch file name plus whatever arguments you intend to pass.
  20. (That tells the system to run a single command out of DOS.)  Look up
  21. ParamCount and ParamStr() to see how Pascal uses command-line parameters.
  22.  
  23. First question second: you know, I addressed this problem just yesterday
  24. trying to write a program.  I concluded that, if you're going to bypass
  25. CRT, you need to do a lot of "manual" work yourself to keep a window
  26. going.  Let me show you the tools I devised:
  27.  
  28.  
  29. ---PROCEDURE ATSCROLL: SCROLLS A SCREEN REGION UP OR DOWN (negative or
  30.    positive number in LINESDOWN, respectively)
  31. }
  32.  
  33. procedure atscroll(x1, y1, x2, y2 : byte; linesdown : integer);
  34. var
  35.   tmpbyte,
  36.   intbyte,
  37.   clearattrib : byte;
  38. begin
  39.   if linesdown <> 0 then
  40.   begin
  41.     clearattrib := foxfore + foxback shl 4;
  42.     x1 := x1 - 1;
  43.     y1 := y1 - 1;
  44.     x2 := x2 - 1;
  45.     y2 := y2 - 1;
  46.     if linesdown > 0 then
  47.       intbyte := $07
  48.     else
  49.       intbyte := $06;
  50.     tmpbyte := abs(linesdown);
  51.     asm
  52.       mov ah, intbyte
  53.       mov al, tmpbyte
  54.       mov bh, clearattrib
  55.       mov ch, y1
  56.       mov cl, x1
  57.       mov dh, y2
  58.       mov dl, x2
  59.       int 10h
  60.     end;
  61.   end;
  62. end;
  63.  
  64. {
  65. ---FUNCTION YPOS: Returns the line the cursor is on.  I wrote it because
  66.    I don't always trust WHEREY (or WHEREX): they report, for example, the
  67.    cursor position relative to a text window.  So I had it lying around,
  68.    and I opted to use it in my routines.
  69. }
  70. function ypos : byte;
  71. var
  72.   tmpbyt : byte;
  73. begin
  74.   asm
  75.     mov ah, 03h
  76.     mov bh, 0
  77.     int 10h
  78.     mov tmpbyt, dh
  79.   end;
  80.   ypos := tmpbyt + 1;
  81. end;
  82.  
  83. {
  84. --- PROCEDURE WRITEANDFIXOVERHANG: I use it in place of WRITELN in my
  85.     program: before writing a line of text, it checks if there's room
  86.     at the bottom of the screen.  If not, it scrolls the screen up
  87.     before writing.  Keep in mind that this program is bent on preserving
  88.     the top three or four screen lines, not the bottom lines.
  89. }
  90. procedure writeandfixoverhang(strin : string);
  91. const
  92.   scrollat : byte = 24;
  93. var
  94.   overhang : byte;
  95. begin
  96.   if ypos >= scrollat then
  97.   begin
  98.     overhang := ypos - scrollat + 1;
  99.     atscroll(0, 4 + overhang, 0, 80, 25, -overhang);
  100.     movecursor(1, ypos - overhang);
  101.   end;
  102.   writeln(strin);
  103. end;
  104.  
  105. {
  106. So assuming your text lines don't get too long (line longer than 160 chars),
  107. these routines will keep the top of your screen from getting eaten.  If you
  108. want to preserve space at the bottom of the screen instead (or both top and
  109. bottom), change WRITEANDFIXOVERHANG.
  110.  
  111. BTW, if there are any compiling problems, let me know.  I took out all the
  112. stuff that applied specifically to my application -- I might have stupidly
  113. changed something you need ...
  114. }